from artifacts.base.attr_type import AttrType
from common.random_util import select_one_from_weight_map
import random


class BonusAttr:
    def get_type_weight_map(self):
        return {
            AttrType.HP: 150,
            AttrType.HP_P: 100,
            AttrType.ATK: 150,
            AttrType.ATK_P: 100,
            AttrType.DEF: 150,
            AttrType.DEF_P: 100,
            AttrType.CRIT_RATE: 75,
            AttrType.CRIT_DMG: 75,
            AttrType.ELEMENTAL: 100,
            AttrType.ENERGY: 100,
        }

    def get_data_table(self):
        return {
            AttrType.HP: [209.13, 239, 268.88, 298.75],
            AttrType.HP_P: [4.08, 4.66, 5.25, 5.83],
            AttrType.ATK: [13.62, 15.56, 17.51, 19.45],
            AttrType.ATK_P: [4.08, 4.66, 5.25, 5.83],
            AttrType.DEF: [16.2, 18.52, 20.83, 23.15],
            AttrType.DEF_P: [5.1, 5.83, 6.56, 7.29],
            AttrType.CRIT_RATE: [2.72, 3.11, 3.5, 3.89],
            AttrType.CRIT_DMG: [5.44, 6.22, 6.99, 7.77],
            AttrType.ELEMENTAL: [16.32, 18.65, 20.98, 23.31],
            AttrType.ENERGY: [4.53, 5.18, 5.83, 6.48],
        }

    def __init__(self, exclude=None, attr_type=None):
        if attr_type is None:
            self.type = select_one_from_weight_map(self.get_type_weight_map(), exclude)
        else:
            self.type = attr_type
        data_list = self.get_data_table()[self.type]
        self.data = data_list[random.randint(0, len(data_list) - 1)]
